import React from 'react'
import {Card, Divider} from "antd";
import {Link} from 'react-router-dom';
import Timeline from "antd/es/timeline/Timeline";
import {getNewBlog} from "../../api/BlogApi";


export default class FreshCard extends React.Component {

    constructor(props) {
        super(props);
        this.state = {itemList: []}
    }


    async componentDidMount() {
        let data = (await getNewBlog(5)).data.list;
        let blogList = [];
        data.forEach((blog) => {
            blogList.push(
                <Timeline.Item color='green' key={data.id}>
                    <Link to={'/blog/' + blog.id}>
                        <span style={{color: 'gray'}}>{blog.title.substring(0, 12)}</span>
                    </Link>
                </Timeline.Item>
            );
        });
        this.setState({itemList:blogList})
    }

    render() {
        return (
            <div>
                <Card style={{width: 300}}>
                    <Divider>最新发布的文章</Divider>
                    <Timeline>
                        {this.state.itemList}
                    </Timeline>
                </Card>
            </div>
        );
    };
}